************************************************************************************************************************
* Replication Do-File for 
*
* Simmons, Joel, Allen Hicken, Ken Kollman, and Irfan Nooruddin. 2016.
* "Party System Structure and its Consequences for Foreign Direct Investment"
* Party Politics.
*
* All models estimated using Stata 14.1.
* Please communicate errors identified to in62@georgetown.edu. Thanks in advance for your help.
************************************************************************************************************************


// NOTE: For convenience, change the working directory below to wherever you've saved the folder
clear // Clear Stata
*cd 


set more off
log using "replication", replace // Start a log file

*******************************************
*******************************************
*******************************************// BEGIN REPLICATION
*******************************************
*******************************************


***************************************
// REPLICATE TABLE 1
***************************************
// NOTE: To replicate these results, you will need to use the TSCS database
clear
use FDI_TSCS
desc // Describe the database
tsset cowcode year // Identify time-series and cross-sectional variables

// Model 1: FDI (%GDP) regressed on Cox-style party nationalization (i.e., party inflation) score
xtpcse dfdi inflationlag dinflation fdilag dfdilag log_rgdpchlag dlog_rgdpch grgdpchlag dgrgdpch  log_openklag dlog_openk log_poplag dlog_pop enpgovlag denpgov log_durablelag dlog_durable year  fe1-fe200  if polity2>=7&polity2!=.&polity2lag!=.&polity2lag>=7&inflationstop!=., pa noconstant
// Store results
estimates store m1

// Model 2: USA capital expenditures regressed on Cox-sytle party nationalization (i.e., party inflation) score
xtpcse dlog_usacapexpend  inflationlag dinflation  log_rgdpchlag dlog_rgdpch grgdpchlag dgrgdpch  log_openklag dlog_openk log_poplag dlog_pop enpgovlag denpgov log_usacapexpendlag d.log_usacapexpendlag log_durablelag dlog_durable year  fe1-fe200  if polity2>=7&polity2!=.&polity2lag!=.&polity2lag>=7&country!=""&inflationstop!=., pa noconstant
// Store results
estimates store m2

// Model 3: FDI regressed on Bochsler party nationalization score
xtpcse dfdi psnsswlag dpsnssw fdilag dfdilag log_rgdpchlag dlog_rgdpch grgdpchlag  dgrgdpch log_openklag dlog_openk log_poplag dlog_pop enpgovlag denpgov  log_durablelag dlog_durable year fe1-fe200  if polity2>=7&polity2!=.&polity2lag!=.&polity2lag>=7&country!=""&psnsswstop!=., pa noconstant
// Store results
estimates store m3

// Put the results in a table
// NOTE: Must have the estout Stata package installed
esttab m1 m2 m3, star(* 0.1 ** 0.05 *** 0.01) label compress se ar2 b(a2) se(a2) title(Table 1: Party System Nationalization and FDI Inflows) drop(fe*)  nogaps  addnotes(L. refers to one period lag of variable; D. refers to differenced variable) 

***************************************
// REPLICATE TABLE 2
***************************************
// NOTE: To replicate these results, you will need to use the cross-sectional database "FDI_XS.dta"

clear
use "FDI_XS.dta"
desc

// Model 1: Bounded-influence estimator

// Step 1: Estimate the model of interest
reg std_taxrev inflation log_rgdpch log_pop log_openk enpgov count_taxrev taxrev africa-eeurope  if polity2>=7&polity2!=.&count_electionyear>=1 

// Step 2: Calculate DFITS and generate weights
predict dfits if e(sample), dfits
gen weight = 1 if dfits <=.34
replace weight = (.34/abs(dfits)) if dfits>.34

// Step 3: Re-estimate the model using weighted-least squares
wls0  std_taxrev inflation log_rgdpch log_pop log_openk enpgov count_taxrev taxrev africa-eeurope  if polity2>=7&polity2!=.&count_electionyear>=1, wvars(weight) type(abse) robust

// Store results
estimates store m4

// Place result in table
esttab m4, star(* 0.1 ** 0.05 *** 0.01) label compress se ar2 b(a2) se(a2) title(Table 2: Party System Nationalization and Tax Volatility) wide drop(mideast  sasia)

***************************************
// REPLICATE FIGURE 1
***************************************
// Note #1: The figure requires use the database of cross-sectional averages between 2003 and 2007, "FDI_XS0307.dta"
// Note #2: Step 3 uses a Weighted-least squares regression developed by Greene. The command is 'wls0'. If you haven't
// installed it, use 'findit wls0' to do so.

clear 
use "FDI_XS0307.dta"
desc
 
 // Estimate the bounded-influence model
 // Step 1: Estimate the model of interest
reg fdi inflation ginidum ix_infgini log_rgdpch dlog_rgdpch log_openk log_pop enpgov log_durable africa-eeurope  if polity2>=7&polity2!=.&count_electionyear>=1&country!="", 

// Step 2: Calculate DFITS and generate weights
predict dfits if e(sample), dfits
gen weight = 1 if dfits <=.34
replace weight = (.34/abs(dfits)) if dfits>.34

// Step 3: Re-estimated the model using weighted-least squares
wls0 fdi inflation ginidum ix_infgini log_rgdpch dlog_rgdpch log_openk log_pop enpgov log_durable africa-eeurope  if polity2>=7&polity2!=.&count_electionyear>=1&country!="", wvars(weight) type(abse) robust

// Store results
estimates store m5

// Graph the results
// First graph them as if Gini dummy variable was continuous
estimates restore m5
#delimit ; 
generate MV=((_n-1)/10);
replace  MV=. if _n>20;
matrix b=e(b); 
matrix V=e(V);
scalar b1=b[1,1]; 
scalar b2=b[1,2];
scalar b3=b[1,3];
scalar varb1=V[1,1]; 
scalar varb2=V[2,2]; 
scalar varb3=V[3,3];
scalar covb1b3=V[1,3]; 
scalar covb2b3=V[2,3];
scalar list b1 b2 b3 varb1 varb2 varb3 covb1b3 covb2b3;
gen conb=.1*(b1+b3*MV) if _n<20;
gen conse=.1*(sqrt(varb1+varb3*(MV^2)+2*covb1b3*MV)) if _n<20; 
gen a=1.96*conse;
gen upper=conb+a;
gen lower=conb-a;
graph twoway line conb   MV if MV<=1 , clwidth(medium) clcolor(black)  
    || line upper  MV if MV<=1, clpattern(dash) clwidth(medium) clcolor(black)  
    || line lower  MV if MV<=1, clpattern(dash) clwidth(medium) clcolor(black) 
   || hist ginidum if e(sample), yaxis(2) bin(10) bfcolor(none) blcolor(gs8) blwidth(thin) percent ytitle(Distribution of Gini Dummy (Percent), axis(2))
  ,   ytitle("Effect of 0.1 Increase in Regionalization", size())  
   xtitle(Gini Dummy Variable)  
   xlabel(0 (1) 1)
  legend(label (1 "Marginal Effect") label (2 "95% Confidence") label (4 "Gini Dummy") order(1 2 4) size(medsmall) row(1) symxsize(*.5)) 
   yline(0, lcolor(black)) note() graphregion(color(white));
#delimit cr

// Then, extract and graph the marginal effect and confidence intervals for when the Gini dummy equals 0 and 1
graph twoway (scatter conb MV, mcolor(black))(rcap  lower upper MV, lcolor(black)) if MV==0|MV==1, yline(0, lcolor(gs8)) graphregion(color(white)) xtitle(Regional Economic Inequality (Gini Coefficient)) ytitle(Effect of 0.1 Increase in Party Regionalization) legend(label(1 "Marginal Effect") label(2 "95% Confidence")) xlabel(0 1) xscale(range(-1 2) )

// Save graph as PDF
graph export "Fig1.pdf", replace



 ***************************************
// REPLICATE FIGURE 2
***************************************
// Figure 2 requires the TSCS database 

clear
use "FDI_TSCS.dta"
tsset cowcode year

// Create interaction term between lagged party nationalization and lagged effective number of government parties
gen ix_infenplag = inflationlag * enpgovlag

// Create an interaction term between differenced party nationalization and differenced effective number of government parties
gen ix_dinfenp = dinflation * denpgov

// Estimate the model
xtpcse dfdi inflationlag enpgovlag ix_infenplag dinflation denpgov ix_dinfenp fdilag dfdilag log_rgdpchlag dgrgdpch dlog_rgdpch grgdpchlag  log_openklag dlog_openk log_poplag dlog_pop  log_durablelag dlog_durable year   fe1-fe200  if polity2>=7&polity2!=.&polity2lag!=.&polity2lag>=7&inflationstop!=., pa noconstant

// Store results
estimates store m6

// Graph the results
estimates restore m6

#delimit ; 
generate MV=((_n-1)/10);
replace  MV=. if _n>90;
matrix b=e(b); 
matrix V=e(V);
scalar b1=b[1,1]; 
scalar b2=b[1,2];
scalar b3=b[1,3];
scalar varb1=V[1,1]; 
scalar varb2=V[2,2]; 
scalar varb3=V[3,3];
scalar covb1b3=V[1,3]; 
scalar covb2b3=V[2,3];
scalar list b1 b2 b3 varb1 varb2 varb3 covb1b3 covb2b3;
gen conb=.1*(b1+b3*MV) if _n<90;
gen conse=.1*(sqrt(varb1+varb3*(MV^2)+2*covb1b3*MV)) if _n<90; 
gen a=1.96*conse;
gen upper=conb+a;
gen lower=conb-a;
graph twoway line conb   MV if MV>=1, clwidth(medium) clcolor(black)  
    || line upper  MV if MV>=1, clpattern(dash) clwidth(medium) clcolor(black)  
    || line lower  MV if MV>=1, clpattern(dash) clwidth(medium) clcolor(black) 
   || hist enpgov if e(sample), yaxis(2) bin(10) bfcolor(none) blcolor(gs8) blwidth(thin) percent ytitle(Distribution Effective Number of Parties (Percent), axis(2))
  ,   ytitle("Effect of Party 0.1 Increase in Regionalization", size())  
   xtitle(Effective Number of Government Parties)  
   xlabel(1 (1) 9)
  legend(label (1 "Marginal Effect") label (2 "95% Confidence") label (4 "ENP") order(1 2 4) size(medsmall) row(1) symxsize(*.5)) 
   yline(0, lcolor(black)) note() graphregion(color(white));
        drop MV conb conse a upper lower;
#delimit cr

// Save the graph
graph export "Fig2.pdf", replace
 ***************************************
// REPLICATE APPENDICES
***************************************
// Start with the TSCS database
clear
use "FDI_TSCS.dta"

// To get list of countries, first re-estimate Model 1 from Table 1
xtpcse dfdi inflationlag dinflation fdilag dfdilag log_rgdpchlag dlog_rgdpch grgdpchlag dgrgdpch  log_openklag dlog_openk log_poplag dlog_pop enpgovlag denpgov log_durablelag dlog_durable year  fe1-fe200  if polity2>=7&polity2!=.&polity2lag!=.&polity2lag>=7&inflationstop!=., pa noconstant

// Then, extract countries in the sample
tab country if e(sample)

// Table A1: Summary statistics from baseline model
sum dfdi inflationlag dinflation fdilag dfdilag log_rgdpchlag dlog_rgdpch grgdpchlag dgrgdpch  log_openklag dlog_openk log_poplag dlog_pop enpgovlag denpgov log_durablelag dlog_durable if e(sample)

 ***************************************

// Table A2: Summary statistics from US Capital Expenditures Model
// First re-estimate the model
xtpcse dlog_usacapexpend  inflationlag dinflation  log_rgdpchlag dlog_rgdpch grgdpchlag dgrgdpch  log_openklag dlog_openk log_poplag dlog_pop enpgovlag denpgov log_usacapexpendlag d.log_usacapexpendlag log_durablelag dlog_durable year  fe1-fe200  if polity2>=7&polity2!=.&polity2lag!=.&polity2lag>=7&country!=""&inflationstop!=., pa noconstant

// Then, summarize the variables
sum dlog_usacapexpend  inflationlag dinflation  log_rgdpchlag dlog_rgdpch grgdpchlag dgrgdpch  log_openklag dlog_openk log_poplag dlog_pop enpgovlag denpgov log_usacapexpendlag d.log_usacapexpendlag log_durablelag dlog_durable if e(sample)

 ***************************************

// Table A3: The Effect of Nationalization as the Geographic Distribution of Wealth Changes

// Check to see if relevant estimates, stored as m5, are in the working directory
estimates dir
// If they are, replicate Table A3 as follow
esttab m5, star(* 0.1 ** 0.05 *** 0.01) label compress se ar2 b(a2) se(a2) title(Table A1: The Effect of Nationalization as the Geographic Distribution of Wealth Changes) wide drop(mideast  sasia)

 ***************************************
// Replicate Table A4: Effect of Party Nationalization as Coalition Size Changes
// Check to make sure relevant estimates, named m6, are in working directory.  
estimates dir
// If so, replicate the results as follows
esttab m6, star(* 0.1 ** 0.05 *** 0.01) label compress se ar2 b(a2) se(a2) title(Table A4: Effect of Party Nationalization as Coalition Size Changes) wide drop(fe*)  nogaps  addnotes(L. refers to one period lag of variable; D. refers to differenced variable) 

 ***************************************
// Table A5: Party System Nationalization and Logged Net FDI Inflows
clear
use "FDI_TSCS.dta"

// Model 1: Full time period
xtpcse dlog_fdidollars_wb_re inflationlag dinflation log_fdidollars_wb_relag dlog_fdidollars_wb_relag log_rgdpchlag dlog_rgdpch grgdpchlag dgrgdpch  log_openklag dlog_openk log_poplag dlog_pop enpgovlag denpgov log_durablelag dlog_durable year  fe1-fe200  if polity2>=7&polity2!=.&polity2lag!=.&polity2lag>=7&inflationstop!=., pa noconstant
estimates store netfdi1

// Model 2: Start sample at 1990
xtpcse dlog_fdidollars_wb_re inflationlag dinflation log_fdidollars_wb_relag dlog_fdidollars_wb_relag log_rgdpchlag dlog_rgdpch grgdpchlag dgrgdpch  log_openklag dlog_openk log_poplag dlog_pop enpgovlag denpgov log_durablelag dlog_durable year  fe1-fe200  if polity2>=7&polity2!=.&polity2lag!=.&polity2lag>=7&inflationstop!=.&year >=1990, pa noconstant
estimates store netfdi2

// Model 3: Start sample at 2000
xtpcse dlog_fdidollars_wb_re inflationlag dinflation log_fdidollars_wb_relag dlog_fdidollars_wb_relag log_rgdpchlag dlog_rgdpch grgdpchlag dgrgdpch  log_openklag dlog_openk log_poplag dlog_pop enpgovlag denpgov log_durablelag dlog_durable year  fe1-fe200  if polity2>=7&polity2!=.&polity2lag!=.&polity2lag>=7&inflationstop!=.&year >=2000, pa noconstant
estimates store netfdi3

// Make the table
esttab netfdi1 netfdi2 netfdi3, star(* 0.1 ** 0.05 *** 0.01) label compress se ar2 b(a2) se(a2) title()  drop(fe*)

*******************************************
*******************************************
*******************************************// END OF REPLICATION
*******************************************
*******************************************

log off 
log close
